﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Krist_em_up
{
    public abstract class Sprite
    {
        protected Rectangle rectangle;
        protected string textureAsset;
        protected Texture2D texture;
        protected Vector2 position, direction, speed;
        protected Kristemup game;
        public Vector2 Position
        {
            get
            {
                return position;
            }
        }

        public Sprite()
        {
            rectangle = new Rectangle();
        }

        public void LoadContent()
        {
           texture = game.Content.Load<Texture2D>(textureAsset);
        }
        public void setPosition(Vector2 v)
        {
            position = v;
        }

        public Rectangle GetRec()
        {
            return rectangle;
        }

        public bool Collision(Sprite sprite)
        {
            return (rectangle.Intersects(sprite.GetRec()));
        }

        public void Update()
        {
            position += speed * direction;
            rectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
        }


        public bool IsOnScreen()
        {
            return (position.X >= game.origin.X && position.Y >= 0 && position.X + texture.Width <= game.game.graphics.PreferredBackBufferWidth + game.origin.X
                && position.Y + texture.Height <= game.game.graphics.PreferredBackBufferHeight);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(texture, new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height), Color.White);
            spriteBatch.End();
        }
    }
}